package com.xiaoniu.forum.web.controller;

import java.util.Arrays;
import java.util.Map;

import com.xiaoniu.forum.common.utils.CommonQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xiaoniu.forum.entity.CommunityTopicCommentEntity;
import com.xiaoniu.forum.service.CommunityTopicCommentService;
import com.xiaoniu.forum.common.utils.PageUtils;
import com.xiaoniu.forum.common.utils.R;



/**
 * 话题评论表
 *
 * @author xiaoniu
 * @email 55333@qq.com
 * @date 2021-03-26 10:14:43
 */
@RestController
@RequestMapping("forum/communitytopiccomment")
public class CommunityTopicCommentController {
    @Autowired
    private CommunityTopicCommentService communityTopicCommentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("forum:communitytopiccomment:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = communityTopicCommentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("forum:communitytopiccomment:info")
    public R info(@PathVariable("id") String id){
		CommunityTopicCommentEntity communityTopicComment = communityTopicCommentService.getById(id);

        return R.ok().put("communityTopicComment", communityTopicComment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("forum:communitytopiccomment:save")
    public R save(@RequestBody CommunityTopicCommentEntity communityTopicComment){
		communityTopicCommentService.save(communityTopicComment);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("forum:communitytopiccomment:update")
    public R update(@RequestBody CommunityTopicCommentEntity communityTopicComment){
		communityTopicCommentService.updateById(communityTopicComment);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("forum:communitytopiccomment:delete")
    public R delete(@RequestBody String[] ids){
		communityTopicCommentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 多条件查询列表
     */
    @PostMapping("/multiConditList")
    @ApiOperation("多条件查询列表")
    public R multiConditList(@RequestBody CommonQueryVo queryVo){
        PageUtils page = communityTopicCommentService.queryPage(queryVo);
        return R.ok().put("page",page);
    }

    /**
     * 查询分页列表 审核列表封装格式
     * @param params 分页参数
     * @return 返回List集合
     */
    @GetMapping("/getListForPass")
    public R getListForPass(@RequestParam Map<String, Object> params){
        PageUtils page = communityTopicCommentService.getListForPass(params);
        return R.ok().put("page",page);
    }

    /**
     * 审核通过
     * @param communityTopicId
     * @return
     */
    @PostMapping("/passed/{topicCommentId}")
    public R passed(@PathVariable String topicCommentId){
        communityTopicCommentService.passed(topicCommentId);
        return R.ok();
    }

    /**
     * 审核不通过
     */
    @PostMapping("/passedFailed/{topicCommentId}")
    public R passedFailed(@PathVariable String topicCommentId,@RequestBody String message){
        communityTopicCommentService.passedFailed(topicCommentId,message);
        return R.ok();
    }

    @PostMapping("disable/{topicCommentId}")
    public R disableById(@PathVariable String topicCommentId){
        communityTopicCommentService.disableById(topicCommentId);
        return R.ok();
    }

    @PostMapping("enabled/{topicCommentId}")
    public R enabledById(@PathVariable String topicCommentId){
        communityTopicCommentService.enabledById(topicCommentId);
        return R.ok();
    }
}
